<?php
function error() {
    global $datas;
    $id = $datas['id'];
    $p = $datas['p'] ?: $p = 0;
    $ciddata = json_decode(file_get_contents('https://api.bilibili.com/x/player/pagelist?bvid='.$id));
    $cid = $ciddata->data[$p]->cid;
    $videodata = json_decode(file_get_contents('https://api.bilibili.com/x/player/playurl?qn=80&bvid='.$id.'&cid='.$cid));
    $video = $videodata->data->durl[0];
    if($video->backup_url[0]) {
        $url = $video->backup_url[0];
    } else {
        $url = $video->url;
    };
    return $url;
};